const allViews = [
    './src/views/index.tsx',
    './src/views/app/index.tsx',
    // './src/views/app/_layout/index.tsx',
    './src/views/detail/_layout.tsx',
    './src/views/user/a.tsx',
    './src/views/user/b.tsx',
    './src/views/user/blog.w.o.layout.tsx',
    './src/views/user/index.tsx',
    './src/views/user/_layout.tsx',
    // './src/views/detail/__id/_layout.tsx',
    './src/views/detail/__id/index.tsx',
    './src/views/detail/__id/info.tsx',
    './src/views/detail/_layout.tsx',
    './src/views/detail/index.tsx',
    './src/views/detail/info/index.tsx',
];
// 分离 layout

const layouts = allViews.filter(view => view.includes('_layout'));

const layoutMap = {};
const regex = /(.*)\/_layout/;

layouts.forEach(layout => {
    const matches = regex.exec(layout);
    if (matches && matches.length > 1) {
        const key = matches[1];
        layoutMap[key] = {
            layoutDir: layout,
            pages: [],
        }
    }
})

const layoutKeys = Object.keys(layoutMap);
layoutKeys.forEach(key => {
    allViews.forEach(item => {
        if (item.includes(key) && item !== layoutMap[key].layoutDir) {
            layoutMap[key].pages.push(item)
        }
    })
})

const checkNormalLayout = (excludeList) => {
    const regList = excludeList.map(item => new RegExp(item));
    return (view) => {
        const result = regList.some(reg => reg.test(view));
        return !result;
    }
}

const checkLayout = checkNormalLayout(layoutKeys);

const normalLayouts = allViews.filter(view => checkLayout(view));


console.log("layoutMap", layoutMap)
console.log("normalLayouts", normalLayouts)